/**
 *create by Jancheng ON 2019/9/9
 * 3D模型渲染器工具
 * */
import * as THREE from 'three';
// 实例化渲染器
function initRender(obj = { domId: '', width: 100, height: 100, cleanColor: '#FFFFFF' }) {
  const renderer = new THREE.WebGLRenderer({
    antialias: true,
    alpha: false,
  });
  renderer.setSize(obj.width, obj.height);
  document.getElementById(obj.domId).appendChild(renderer.domElement);
  renderer.setClearColor(obj.cleanColor, 0);
  return renderer;
}
function renderModel(render = new THREE.WebGLRenderer(), scene = new THREE.Scene(), camera = new THREE.PerspectiveCamera(), controls = null) {
  render.clear();
  if (controls != null) {
    controls.update();
  }
  requestAnimationFrame(() => {
    renderModel(render, scene, camera);
  });
  render.render(scene, camera);
}
export default {
  initRender,
  renderModel,
};
